/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BaoCaoDoanhSoInternalFrame.java
 *
 * Created on Jul 10, 2010, 8:56:20 PM
 */

package GUI;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author May2
 */
public class BaoCaoDoanhSoInternalFrame extends javax.swing.JInternalFrame {

    public void hienThiBaoCao(int thang){
//        ArrayList<ThongKePOJO> list = ThongKeBUS.selectBaoCaoDoanhSoThang(thang);
//        //Tạo các cột trên jtbDanhSach
//        DefaultTableModel dtm = new DefaultTableModel();
//        dtm.addColumn("STT");
//        dtm.addColumn("Đại Lý");
//        dtm.addColumn("Số Phiếu Xuất");
//        dtm.addColumn("Tổng Trị Giá");
//        dtm.addColumn("Tỷ Lệ");
//
//        //Tạo model
//        dtm.setRowCount(list.size());
//        for(int i=0; i<list.size(); i++){
//            dtm.setValueAt(i+1, i, 0);
//            dtm.setValueAt(list.get(i).getTenDaiLy(), i, 1);
//            dtm.setValueAt(list.get(i).getSoPhieuXuat(), i, 2);
//            dtm.setValueAt(list.get(i).getTongTriGia(), i, 3);
//            dtm.setValueAt(list.get(i).getTyLe(), i, 4);
//        }
//
//        //Gán model cho JTable
//        this.jtbDanhSach.setModel(dtm);
//        this.jtbDanhSach.changeSelection(0, 0, false, false);
    }
    /** Creates new form BaoCaoDoanhSoInternalFrame */
    public BaoCaoDoanhSoInternalFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbDanhSach = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jbtThongKe = new javax.swing.JButton();
        jbtThoat = new javax.swing.JButton();
        jlbThang = new javax.swing.JLabel();
        jcbThang = new javax.swing.JComboBox();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("BAO CAO DOANH SO");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 237, Short.MAX_VALUE)
        );

        jtbDanhSach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jtbDanhSach);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Báo Cáo Doanh Số");

        jbtThongKe.setText("Thống Kê");
        jbtThongKe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThongKeActionPerformed(evt);
            }
        });

        jbtThoat.setText("Thoát");
        jbtThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThoatActionPerformed(evt);
            }
        });

        jlbThang.setText("Tháng :");

        jcbThang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbThangActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 528, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(187, 187, 187)
                                .addComponent(jbtThongKe)
                                .addGap(50, 50, 50)
                                .addComponent(jbtThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(170, 170, 170)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(207, 207, 207)
                        .addComponent(jlbThang)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcbThang, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbThang)
                    .addComponent(jcbThang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbtThoat)
                            .addComponent(jbtThongKe))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThoatActionPerformed
        // TODO add your handling code here:
        int reply = JOptionPane.showConfirmDialog(this, "Bạn có muốn thoát", "Thông báo", WIDTH);
        if(reply == JOptionPane.OK_OPTION){
            this.dispose();
        }
    }//GEN-LAST:event_jbtThoatActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
        for(int i=1; i<=12; i++){
            String str = "Tháng "+i;
            Vector ct = new Vector();
            ct.add(i);
            ct.add(str);
            str="";
            //Thêm một dòng vào model của JComboBox
            dcbm.addElement(ct);
        }
        //Gán model cho JComboBox
        this.jcbThang.setModel(dcbm);

        DateFormat dateFormat = new SimpleDateFormat("MM");
        java.util.Date date = new java.util.Date();
        int thang = Integer.parseInt(dateFormat.format(date));
        //this.hienThiBaoCao(thang);
    }//GEN-LAST:event_formInternalFrameOpened

    private void jbtThongKeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThongKeActionPerformed
        // TODO add your handling code here:
//        Vector vt = (Vector)this.jcbThang.getSelectedItem();
//        int maThang = (Integer)vt.get(0);
//
//        int coBaoCao = ThongKeBUS.coBaoCaoDoanhSoCuaThang(maThang);
//        if(coBaoCao==0){
//            ThongKeBUS.baoCaoDoanhSoThang(maThang);
//            JOptionPane.showMessageDialog(this, "Thống kê thành công");
//        } else {
//            ThongKeBUS.updateBaoCaoDoanhSoThang(maThang);
//            JOptionPane.showMessageDialog(this, "Cập nhật thành công");
//        }
//        this.hienThiBaoCao(maThang);
    }//GEN-LAST:event_jbtThongKeActionPerformed

    private void jcbThangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbThangActionPerformed
        // TODO add your handling code here:
        Vector vt = (Vector)this.jcbThang.getSelectedItem();
        int maThang = (Integer)vt.get(0);
        this.hienThiBaoCao(maThang);
    }//GEN-LAST:event_jcbThangActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtThoat;
    private javax.swing.JButton jbtThongKe;
    private javax.swing.JComboBox jcbThang;
    private javax.swing.JLabel jlbThang;
    private javax.swing.JTable jtbDanhSach;
    // End of variables declaration//GEN-END:variables

}
